package ru.spbau.database.group3.engine;

import ru.spbau.database.group3.filesAndAccess.Record;
import ru.spbau.database.group3.parser.ConditionOperator;

import java.io.IOException;

/**
 * @author: stas
 * @date: 2/4/13
 * @time: 3:04 PM
 */
public class Condition {

    public Condition(Column column, Object value, ConditionOperator cOp) {
        this.column = column;
        this.value = value;
        this.cOp = cOp;
    }

    public boolean check(Record r) throws IOException {
        Object recordValue = r.getColumnValue(column);
        return cOp.checkComparison(column.getType().compareTo(recordValue, value));
    }

    public Column getColumn() {
        return column;
    }

    public Object getValue() {
        return value;
    }

    public ConditionOperator getOperator() {
        return cOp;
    }

    private Column column;
    private Object value;
    private ConditionOperator cOp;
}
